/*タイムテーブルの全て、トラック、跳躍、投てき、道路競技クリック時の種目NO設定。最終的にはテーブル取得を目指す*/
USE [NANS21V]
GO

/****** Object:  UserDefinedFunction [dbo].[TimetableSelect]    Script Date: 04/24/2014 13:31:12 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TimetableSelect]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[TimetableSelect]
GO

USE [NANS21V]
GO

/****** Object:  UserDefinedFunction [dbo].[TimetableSelect]    Script Date: 04/24/2014 13:31:12 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[TimetableSelect]
(
	@SYUMOKUKUBUN int
)
RETURNS  varchar(300)
AS
BEGIN
	DECLARE @return varchar(300)
	IF @SYUMOKUKUBUN = 1
		SET @return = '1,2,3,4'--トラック
		
	ELSE IF @SYUMOKUKUBUN = 2
		SET @return = '5,6'--跳躍
		
	ELSE IF @SYUMOKUKUBUN = 3
		SET @return = '7'--投てき
		
	ELSE IF @SYUMOKUKUBUN = 4
		SET @return = '4'--ロード
		
	ELSE 
	  BEGIN
		
		/*
		--ALL(in 最大1000個？)
		SELECT Count(distinct syumokukubun) from tbl_SYUMOKU_MASTER
		  Set @i = 1
		  WHILE @i <= @Count
		  BEGIN
		  
		    set @i = @i + 1;
		  END --while  
		SET @return = 'LIKE %'--全て。もしくは設定以外。
		*/
		SET @return = 'select distinct syumokukubun from tbl_SYUMOKU_MASTER'
      END

	RETURN @return

END
GO

